export const CONFIG_SPAN_BREAKPOINTS: Record<BreakPointType, number> = {
  xs: 12,
  sm: 12,
  md: 8,
  lg: 6,
  xl: 4,
  xxl: 4,
};

export type BreakPointType = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';

export type BreakPoint = {
  pointWidth: number;
  pointType: BreakPointType;
};

const BreakPointDict: BreakPoint[] = [
  { pointType: 'xs', pointWidth: 0 }, // 手机
  { pointType: 'sm', pointWidth: 513 }, // 手机
  { pointType: 'md', pointWidth: 768 }, //平板
  { pointType: 'lg', pointWidth: 992 }, //桌面显示器
  { pointType: 'xl', pointWidth: 1200 }, //大桌面显示器
  { pointType: 'xxl', pointWidth: 1600 }, //大桌面显示器
];

export function getBreakPoint(size: number) {
  const arr = BreakPointDict.map((v) => ({ ...v })).sort((a, b) => {
    return a.pointWidth - b.pointWidth;
  });
  let pointType = arr[0].pointType;

  for (let i = 0; i < arr.length; i++) {
    if (size >= arr[i].pointWidth) {
      pointType = arr[i]?.pointType;
    }
  }
  return pointType;
}

export function getSpanFromPoint(size: BreakPointType | number): number {
  if (typeof size === 'string') {
    return CONFIG_SPAN_BREAKPOINTS[size];
  } else {
    return getSpanFromPoint(getBreakPoint(size));
  }
}
